﻿using Microsoft.Extensions.Configuration;
using WH.Common.Config.Options;

namespace WH.Common.Config
{
    public class ConfigurationCenter : IConfigurationCenter
    {
        private IConfiguration _configuration { get; set; }
        public ConfigurationCenter(IConfiguration configuration)
        {
            _configuration = configuration;

            //var configBuilder = new ConfigurationBuilder()
            //    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            //    .Add(new DbConfigExtensions());

            //_configuration = configBuilder.Build();
            //_configuration.GetReloadToken().RegisterChangeCallback(state =>
            //{
            //    _configuration = configBuilder.Build();
            //}, _configuration);

        }

        public string ConnectionString => _configuration.GetValue<string>("ConnectionString");

        public string? DbType => _configuration.GetValue<string>("DbType");

        public JwtsettingOptions JwtsettingOptions => _configuration.GetSection("JwtSettings").Get<JwtsettingOptions>() ?? new JwtsettingOptions();

        public CacheOpttions CacheOpttions => _configuration.GetSection("CacheOpttions").Get<CacheOpttions>() ?? new CacheOpttions();

        public SwaggerOptions SwaggerOptions => _configuration.GetSection("Swagger").Get<SwaggerOptions>();

        public OperationLogOptions OperationLogOptions => _configuration.GetSection("OperationLog")?.Get<OperationLogOptions>() ?? new OperationLogOptions();


        public RedisOptions RedisOptions => _configuration.GetSection("RedisOptions").Get<RedisOptions>() ?? new RedisOptions();
        
        public ReqRespEncryptOptions ReqRespEncryptOptions => _configuration.GetSection("ReqRespEncryptOptions").Get<ReqRespEncryptOptions>() ?? new ReqRespEncryptOptions();
        public VideoOptions VideoOptions => _configuration.GetSection("VideoOptions").Get<VideoOptions>() ?? new VideoOptions();
    }
}
